﻿using System;
using System.Collections.Generic;
using System.Linq;
using Tools.Domain.Specifications;

namespace Webshop20.Domain.Reporting.Core
{
    public class Customer
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime LastOrderDate { get; set; }

        public Order[] Orders { get; set; }

        public Order LastOrder 
        { 
            get
            {
                return Orders
                    .OrderBy(o => o.Date)
                    .FirstOrDefault();
            }
            
        }

        public IEnumerable<Order> GetOrderBySpecification(ISpecification<Order> orderSpecification)
        {
            //return Orders
            //        .Where(o=>orderSpecification.IsSatisfiedBy(o));

            return Orders
                .Where(orderSpecification.AsPredicate());
        }

        public IEnumerable<Order> GetOrdersWithinRange(DateTime minimumDate, DateTime maximumDate)
        {
            return GetOrderBySpecification(new OrderWithinSpecification(minimumDate, maximumDate));
        }
    }
}